﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using MySql.Data.MySqlClient;

namespace HRForm
{
    public partial class EmployeeInfoForm : Form
    {
        public EmployeeInfoForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connStr = ConfigurationManager.AppSettings["MySqlConnStr"];//;MySQL 数据库连接字符串;
            string sqlCommand = "";
            if (textBox1.Text.Trim() != "")
            {

                sqlCommand = "select emp_number,employee_id,emp_lastname,emp_firstname,emp_middle_name,emp_smoker,emp_birthday,nation_code,emp_gender,emp_marital_status,emp_status,job_title_code,eeo_cat_code,emp_street1,emp_street2,city_code,coun_code,provin_code,emp_zipcode,emp_hm_telephone,emp_mobile,emp_work_telephone,emp_work_email,joined_date,emp_oth_email from hs_hr_employee where emp_number="+Convert.ToInt32(textBox1.Text.Trim());
            }
            else
            {
                sqlCommand = "select emp_number,employee_id,emp_lastname,emp_firstname,emp_middle_name,emp_smoker,emp_birthday,nation_code,emp_gender,emp_marital_status,emp_status,job_title_code,eeo_cat_code,emp_street1,emp_street2,city_code,coun_code,provin_code,emp_zipcode,emp_hm_telephone,emp_mobile,emp_work_telephone,emp_work_email,joined_date,emp_oth_email from hs_hr_employee";

            }

            MySqlConnection conn = new MySqlConnection(connStr);
            try
            {
                conn.Open();
            }
            catch
            {
                throw;
            }

            try
            {

                MySqlDataAdapter myadp = new MySqlDataAdapter(sqlCommand, conn);
                DataSet ds = new DataSet();
                myadp.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];
                MessageBox.Show("本次查询完毕!");
            }
            catch
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }

        private void 导出到excelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("emp_number", "员工序号");
            dic.Add("employee_id", "工号");
            dic.Add("emp_lastname", "姓");
            dic.Add("emp_firstname", "名");
            dic.Add("emp_middle_name", "派");
            dic.Add("emp_smoker", "未知");
            dic.Add("emp_birthday", "出生年月");
            dic.Add("nation_code", "国家代码");
            dic.Add("emp_gender", "性别");
            dic.Add("emp_marital_status", "婚姻状况");
            dic.Add("emp_status", "员工状态");
            dic.Add("job_title_code", "职位代码");
            dic.Add("eeo_cat_code", "未知2");
            dic.Add("emp_street1", "现居住地");
            dic.Add("emp_street2", "家乡住址");
            
            dic.Add("city_code", "城市");
            dic.Add("coun_code", "国家简码");
            dic.Add("provin_code", "省");
            dic.Add("emp_zipcode", "邮编");
            dic.Add("emp_hm_telephone", "家乡电话");
            dic.Add("emp_mobile", "手机号");
            dic.Add("emp_work_telephone", "工作电话");
            dic.Add("emp_work_email", "工作邮箱");
            dic.Add("joined_date", "入职时间");
            dic.Add("emp_oth_email", "其他邮箱");

            HRForm.ReadWriteExcel.ExportTasks(dataGridView1, dic);
        }

        private void RightClick_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                contextMenuStrip1.Show(dataGridView1, e.Location);
            }
        }

        
    }
}
